2024 Method
Changes 0
M

WorksharingUtils.CheckoutWorksets

Description:
Obtains ownership for the current user of as many specified worksets as possible.
Remarks:

For best performance, check out all worksets in one big call, rather than many small calls.

When there comes a contention error when locking the central model, this API would wait and retry endlessly until getting the lock of the central model.

Overloads (2):
CheckoutWorksets(Document,ICollection[WorksetId])
public static ICollection<WorksetId> CheckoutWorksets(
	Document document,
	ICollection<WorksetId> worksetsToCheckout
)
Return Value ICollection<WorksetId> The ids of all specified worksets that are now owned, including all that were owned prior to the function call.
void CheckoutAllViewWorksets(Document doc)
{
    FilteredWorksetCollector collector = new FilteredWorksetCollector(doc);

    // find all view worksets
    collector.OfKind(WorksetKind.ViewWorkset);
    ICollection<WorksetId> viewworksets = collector.ToWorksetIds();
    ICollection<WorksetId> checkoutworksets = WorksharingUtils.CheckoutWorksets(doc, viewworksets);
    TaskDialog.Show("Checked out worksets", "Number of worksets checked out: " + checkoutworksets.Count);
}